<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>发起请求</button>
    <h3></h3>
    <!-- <script src="./03.Promise基本用法.js"></script> -->
    <script src="./Promise封装请求方式.js"></script>

    <script>
        const btn = document.querySelector('button')
        btn.addEventListener('click',function () {
            // const res = await harryAjax({ method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' })
            // console.log(res);
            // const {data} =res
            // data.forEach(item=>{
            //     console.log(item)
            // })
            const dataObj = {bookname: '四大名著', author: '四个人', publisher: '北京图书出版社'}
            Promise.all([
            harryAjax({ method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' ,data:{id:1}}),
            harryAjax({ method: 'POST', url: 'http://ajax-base-api-t.itheima.net/api/post' ,dataObj}),
            ]).then(res=>{
                console.log(res)
                if(res) document.querySelector('h3').innerHTML = '我是首页'
            }).catch(err=> {
            //    console.log(err)
                if(err) document.querySelector('h3').innerHTML = err
            })
        })
    </script>
</body>

</html>